package it.rap.applications.birt.report.core;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.service.ServiceHandler;
import org.eclipse.rap.rwt.service.ServiceManager;
import org.eclipse.swt.widgets.Composite;

import it.rap.applications.birt.report.services.BirtDownloadServiceHandler;
import it.rap.applications.birt.report.services.DownloadServiceHandler;
import it.rap.applications.container.IContainerPage;
import it.rap.applications.contributions.manager.services.IDownloadServiceHandler;

public class BirtReport implements IContainerPage {

	@Override
	public void createControl(Composite parent) {
		ServiceManager manager = RWT.getServiceManager();
		IDownloadServiceHandler handler = new DownloadServiceHandler();	
		IDownloadServiceHandler birtHandler = new BirtDownloadServiceHandler();	
		
		try{
			manager.registerServiceHandler( DownloadServiceHandler.ID, (ServiceHandler)handler );
			manager.registerServiceHandler( BirtDownloadServiceHandler.ID, (ServiceHandler)birtHandler );
		} catch( IllegalArgumentException e ){
			Logger.getAnonymousLogger().log(Level.SEVERE, e.getMessage());
		}
		HTMLView htmlView = new HTMLView();		
		htmlView.createPartControl(parent);
		try {
			htmlView.createReport();
			htmlView.doReport();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
